package com.ff.ticket.service.impl;

import com.ff.ticket.domain.Show;
import com.ff.ticket.repository.ShowRepository;
import com.ff.ticket.service.IShowService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShowService implements IShowService {

    @Resource
    private ShowRepository showRepository;


    @Override
    public List<Show> findShowsByStatusAndTag(String status,String tag) {
        if(null != status && status.length()>0){
            if(null != tag && tag.length()>0) {
                return showRepository.findShowsByStatusAndTag(status,tag);
            }else {
                return showRepository.findShowsByStatus(status);
            }
        }else {
            if(null != tag && tag.length()>0) {
                return showRepository.findShowsByTag(tag);
            }else {
                return showRepository.findAll();
            }
        }

    }

    @Override
    public Show findShowById(String id) {
        return showRepository.findShowById(Integer.valueOf(id));
    }

    @Override
    public void updateShow(Show show) {
        showRepository.save(show);
    }

    @Override
    public void deleteShow(Show show) {
        showRepository.delete(show);
    }
}
